﻿using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using LiveTiss.Schemas;

namespace LiveTiss.Guias.UserControls
{
    public partial class InternacaoObstetrica : UserControl
    {
        #region Value

        public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value",
            typeof(ct_internacaoObstetrica), typeof(InternacaoObstetrica), new PropertyMetadata(null));

        public ct_internacaoObstetrica Value
        {
            get { return (ct_internacaoObstetrica)GetValue(ValueProperty); }
            set { SetValue(ValueProperty, value); }
        }

        #endregion

        public InternacaoObstetrica()
        {
            this.DataContext = this;

            if (this.Value == null)
            {
                this.Value = new ct_internacaoObstetrica()
                {
                    aborto = false,
                    abortoSpecified = true,
                    atendimentoRNSalaParto = false,
                    atendimentoRNSalaPartoSpecified = true,
                    baixoPeso = false,
                    baixoPesoSpecified = true,
                    complicacaoNeonatal = false,
                    complicacaoNeonatalSpecified = true,
                    complicacaoPeriodoPuerperio = false,
                    complicacaoPeriodoPuerperioSpecified = true,
                    declaracoesNascidosVivos = new List<string>(),
                    emGestacao = false,
                    emGestacaoSpecified = true,
                    obitoMulher = st_obitoMulher.Item1,
                    obitoMulherSpecified = true,
                    partoCesareo = false,
                    partoCesareoSpecified = true,
                    partoNormal = false,
                    partoNormalSpecified = true,
                    qtdNascidosMortos = string.Empty,
                    qtdNascidosVivosTermo = string.Empty,
                    qtdVivosPrematuros = string.Empty,
                    transtornoMaternoRelGravidez = false,
                    transtornoMaternoRelGravidezSpecified = true
                };
            }

            InitializeComponent();
        }

        private void btnAdicionarDeclaracao_Click(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrEmpty(txtDeclaracao.Text.Trim()))
            {
                var list = this.Value.declaracoesNascidosVivos.GetRange(0, this.Value.declaracoesNascidosVivos.Count);

                list.Add(txtDeclaracao.Text);

                this.Value.declaracoesNascidosVivos = list;
            }
            txtDeclaracao.Text = string.Empty;
        }

        private void btnRemoverDeclaracao_Click(object sender, RoutedEventArgs e)
        {
            if (lbxDeclaracao.SelectedItem is string && !string.IsNullOrEmpty(lbxDeclaracao.SelectedItem.ToString()))
            {
                var list = this.Value.declaracoesNascidosVivos.GetRange(0, this.Value.declaracoesNascidosVivos.Count);

                list.Remove(lbxDeclaracao.SelectedItem.ToString());

                this.Value.declaracoesNascidosVivos = list;
            }
            txtDeclaracao.Text = string.Empty;
        }
    }
}
